package com.allen.app.common.config.swagger.reader;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.OperationModelsProviderPlugin;
import springfox.documentation.spi.service.contexts.RequestMappingContext;
import springfox.documentation.swagger.common.SwaggerPluginSupport;

/**
 * 收集所有Model到ApiReadContext
 * @author Leon (234239150@qq.com) created in 15:42 18.9.12
 */
@Slf4j
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1000)
public class ApiModelFieldsReader implements OperationModelsProviderPlugin {

    private final ApiReaderContext apiReaderContext;

    public ApiModelFieldsReader(ApiReaderContext apiReaderContext) {
        this.apiReaderContext = apiReaderContext;
    }

    @Override
    public void apply(RequestMappingContext context) {
        context.getModelMap().forEach((name, model) -> apiReaderContext.getModels().put(name, model));
   }

    @Override
    public boolean supports(DocumentationType delimiter) {
        return true;
    }
}
